package br.org.flavico.acheme.persistence.dao.implementation;

import java.util.List;


import javax.persistence.EntityManager;

import br.org.flavico.acheme.bean.Local;
import br.org.flavico.acheme.factory.EMF;
import br.org.flavico.acheme.persistence.dao.ILocalDAO;

public class LocalDAO implements ILocalDAO{

	@Override
	public void saveOrUpdate(Local local) {
    	EntityManager em = EMF.get().createEntityManager();
	    try {
	    	em.persist(local);
        } finally {
            em.close();
        }		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Local> listaLocais() {
    	EntityManager em = EMF.get().createEntityManager();
    	List<Local> lista = null;
    	try {
    		lista = em.createNamedQuery("TodosLocais").getResultList();
    	} finally{
    		em.close();
    	}
    	return lista;
		
	}

}